package com.example.demo.service;

import com.example.demo.config.datasource.DataSourceConfig;
import com.example.demo.config.datasource.TargetDataSource;
import com.example.demo.repository.entity.UserEntity;
import com.example.demo.repository.jpa.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    @TargetDataSource(name = DataSourceConfig.PRIMARY_DATA_SOURCE)
    public UserEntity selectFromPrimary() {
        return userRepository.findById(1L).get();
    }

    @TargetDataSource(name = DataSourceConfig.SECOND_DATA_SOURCE)
    public UserEntity selectFromSecond() {
        return userRepository.findById(1L).get();
    }

}
